package com.ant.myagile.test.controller
import com.ant.myagile.Memberimport com.ant.myagile.Projectimport com.ant.myagile.Teamimport com.ant.myagile.backlog.RetrospectiveResultimport com.ant.myagile.backlog.RetrospectiveResultController;
import com.ant.myagile.backlog.Sprint

import static org.junit.Assert.*

import grails.test.mixin.*
import grails.test.mixin.support.*
import org.apache.tools.ant.taskdefs.Length;import org.codehaus.groovy.grails.web.json.JSONObjectimport org.junit.*

/** * See the API for {@link grails.test.mixin.support.GrailsUnitTestMixin} for usage instructions */
@TestFor(RetrospectiveResultController)
@Mock([Member, Project, Team, Sprint, RetrospectiveResult])

class RetrospectiveResultControllerTests {

	void setUp() {
		Member.metaClass.encodePassword = { -> }		// member		def khangLe = new Member(username: "khang.le@axonactive.vn", password: '123213', position: "Junior Java Developer", mobile: "972 731 980").save(failOnError: true)		def hieuLam = new Member(username: "hieu.lam@axonactive.vn", password: "123456", position: "Junior Java Developer", mobile: "123 911 602").save(failOnError: true)		def hanhNguyen = new Member(username: "hanhnguyen@axonactive.vn", password: "123456", position: "Junior Java Developer", mobile: "090 145 333").save(failOnError: true)		/* project */		Project myAgile = new Project(projectName: "My Agile", description: "Scrum project management", owner: hieuLam).save(failOnError: true)		/* team */		Team ant = new Team(teamName: "Ant", mailGroup: "ant@axonactive.vn", establishedDate: new Date()).save(failOnError: true)		/* sprint */		Sprint antSp0 = new Sprint(sprintName: "Ant.Sprint-0", status: "closed", dateStart:new Date(), dateEnd: new Date(), team: ant).save(failOnError: true)		Sprint antSp1 = new Sprint(sprintName: "Ant.Sprint-1", status: "closed", dateStart: new Date(), dateEnd: new Date(), team: ant).save(failOnError: true)		/* impediment */		RetrospectiveResult antSp0Im0 = new RetrospectiveResult(type: "unhappy", description: "So confused", status: "Unsolved", sprint: antSp0, project: myAgile, date: new Date("06/11/2013"), owner : Member.get(1)).save(failOnError: false)		RetrospectiveResult antSp0Im1 = new RetrospectiveResult(type: "unhappy", description: "So confused", status: "Unsolved", sprint: antSp0, project: myAgile, date: new Date("06/10/2013"), owner : Member.get(2)).save(failOnError: false)		RetrospectiveResult antSp0Im2 = new RetrospectiveResult(type: "happy", description: "Task solved", status: "Unsolved", sprint: antSp1, project: myAgile, date: new Date("06/05/2013"), owner : Member.get(3)).save(failOnError: false)
	}

	void tearDown() {	}	void testUpdatType(){		def antSp0Im0 = RetrospectiveResult.get(1)		params["id"] = antSp0Im0.id		def retro = controller.updateType()		JSONObject data = (JSONObject) response.getJson()		assertEquals("Solved", data.retro.status)	}	void testgetRetro(){		def antSp0Im0 = RetrospectiveResult.get(1)		params["id"] = antSp0Im0.id		def retro = controller.getRetro()		JSONObject data =(JSONObject) response.getJson()		assertEquals("So confused", data.retro.description)	}	void testUpdateRetro(){		def antSp0Im0 = RetrospectiveResult.get(1)		params["id"] = antSp0Im0.id		params["de"] = "happy"		def retro = controller.updateRetro()		JSONObject data =(JSONObject) response.getJson()		assertEquals("happy", data.retro.description)	}	void testDelRetro(){		def antSp0Im0 = RetrospectiveResult.get(1)		params["id"] = antSp0Im0.id		def result = controller.delRetro()		assertEquals(result,null)	}}
